package net.hctek.identity.util;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PropertyUtil {

	private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class);
	private static Properties props = new Properties();
	private HashMap<String, String> Propertie_content;
	
	
	   static {  
	        try {  
	            //PropertiesHelper.class.getResourceAsStream("env.properties"); // /com/cici/conf/env.properties  
	            //ClassLoader.getSystemResourceAsStream("env.properties");  
	            InputStream is = PropertyUtil.class.getClassLoader().getResourceAsStream("qrcode_temp.properties");  
	            props.load(is);  
	            is.close();  
	        } catch (Exception e) {  
	        	logger.error("qrcode_temp.properties文件找不到");  
	        }  
	    }
	
	synchronized public HashMap<String, String> getProperty(String key){
		
		Propertie_content = new HashMap<>();
		Iterator<String> it = props.stringPropertyNames().iterator();
			 while(it.hasNext()){
				 key=it.next();
				 Propertie_content.put(key, props.getProperty(key)); 
				} 
	     return Propertie_content;
	}
	
	
	synchronized public void setProperty(String key,String Value){
		try {
			File file = new File(PropertyUtil.class.getClassLoader().getResource(".").getPath()+File.separator+"qrcode_temp.properties");   
			FileOutputStream oFile = new FileOutputStream(file, true);
			props.setProperty(key, Value);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
}	
